#### "Gender Inequality and Authoritarian Regimes" ####
# authors: "Lars Pelke"
# date: 2020-01-20
# clear workspace
rm(list=ls())
#libraries
library(tidyverse)
library(ggpubr)
library(panelr)
library(readstata13)
library(texreg)
library(dotwhisker)
library(broom.mixed)
library(countrycode)
library(lme4)
library(sjPlot)
library(sjmisc)
library(lfe)
library(MCMCpack)
# set working directory
setwd("M:/Promotion/Paper/Gender Inequality/calculations/data/rawdata")
##Import VDEM DATA
vdem <- read_csv("vdem_9/V-Dem-CY-Full+Others-v9.csv")
vdem <- vdem %>%
rename(cown = COWcode)
vdem$cown <- countrycode(vdem$country_name, "country.name", "cown", warn = TRUE)
##Importatn Wahman, Teorell and Hadenius data ##
library(democracyData)
wth <- wahman_teorell_hadenius
wth$cown <- countrycode(wth$wahman_teorell_hadenius_country, "country.name", "cown", warn = TRUE)
## Import EPR data ##
eprlong <- read.csv("epr/EPR-2018.1.1.csv", as.is = T) %>%
rename(country = statename) %>%
arrange(country)
# compare country names in EPR to dataset
setdiff(ds.fullraw$country, eprlong$country)
# recode differing country names
eprlong$country[eprlong$country == "Czech Republic"] <- "Czechia"
eprlong$country[eprlong$country == "Republic of Korea"] <- "South Korea"
eprlong$country[eprlong$country == "Serbia" |
eprlong$country == "Serbia and Montenegro"] <- "Yugoslavia/Serbia"
# transform into country-year data
eprlongcy <- eprlong %>%
rowwise() %>%
do(data.frame(country = .$country,
from = .$from,
to = .$to,
year = seq(.$from, .$to, by = 1),
group = .$group,
gwgroupid =.$gwgroupid,
umbrella = .$umbrella,
size = .$size,
status = .$status)) %>%
arrange(country, year)
# reduce dataset
epr <- eprlongcy %>%
filter(year >= 1964)
# add country-year variable
epr$countryyear <- paste(epr$country, epr$year)
# create exclusion dummy variable
epr <- epr %>%
mutate(exclusion = if_else(status == "DISCRIMINATED"  |
status == "POWERLESS" |
status == "SELF-EXCLUSION", 1, 0))
# create exclusion ratio variable
epr <- epr %>%
group_by(country, year) %>%
summarise(eprratio = sum(size[exclusion == 1]))
epr$cown <- countrycode(epr$country, "country.name", "cown", warn = TRUE)
epr <- epr %>%
ungroup()%>%
dplyr:: select(cown, year, eprratio)
#### Create final basic dataset ####
vdem <- vdem %>%
left_join(wth, c("cown", "year"))
vdem <- vdem %>%
left_join(epr, by = c("cown", "year"))
rm(epr, eprlong, eprlongcy)
#### Filter authoritarian regimes based on Hadenius et al. ####
vdem <- vdem %>%
filter(year >=1970) %>%
filter(regime1ny %in% c(1, 2, 3, 4, 9)) # 3751 country-years that are an autocracy
vdem <- vdem %>%
mutate(wth_regime = case_when(regime1ny==1 ~ "monarchy",
regime1ny==2 ~ "military",
regime1ny==3 ~ "one-party",
regime1ny==4 ~ "multi-party",
regime1ny==9 ~ "no-party"))
table(vdem$wth_regime)
# military    monarchy multi-party    no-party   one-party
# 972         453        1479          36         811
#### Analysis of (political) exclusion by gender ####
#### Building and reshaping Variables ####
vdem <- vdem %>%
dplyr::select(cown, country_name, country_id, year, wth_regime, eprratio, e_mipopula, e_wb_pop,
e_migdppcln, starts_with("e_total"), v2lgfemleg , v2elfemrst, e_pefeliex, v2lgqugen, v2elloelsy,
v2elparlel, starts_with("v2exl_legitideolcr"), v2exl_legitideol, v2exl_legitlead, v2exl_legitperf,
v2exl_legitratio, v2pepwrgen, v2peasjgen, v2peasbgen, v2xpe_exlgender, starts_with("v2elmulpar"),
v2xps_party, v2psorgs, v2psprbrch, v2psprlnks, v2psplats, v2pscohesv, v2x_regime, v2clgencl,
v2peapsgen,v2peasjgen, v2peasbgen)
## generate variables ##
vdem <- vdem %>%
mutate(e_wb_pop_ln = log10(e_wb_pop))
vdem <- vdem %>%
mutate(v2lgqugen = ifelse(v2lgqugen>=1, 1, 0))
## Rescale Natural Resource Variable ##
vdem <- vdem %>%
mutate(e_total_resources_income_pc = e_total_resources_income_pc/1000)
summary(vdem$e_total_resources_income_pc)
#### Generate Sample ####
vdem <- distinct(vdem, country_id, year, .keep_all= TRUE)
# delete those countries with less than 3 country-year observations to dela with singular fit
vdem <- vdem %>% # delete those countries with less than 3 country-year observations to dela with singular fit
dplyr::group_by(cown) %>%
mutate(num_years = max(year) - min(year)) %>%
filter(num_years >= 5) %>%
ungroup(cown)
saveRDS(vdem, file = "calculations/data/vdem_wth_merged.rds")
#### Additional Figure review ####
vdem <- vdem %>%
group_by(cown) %>%
fill(v2elmulpar_osp)
summary(vdem$v2elmulpar_osp) # compare Lührmann et al. 2018
vdem <- vdem %>%
mutate(v2elmulpar_osp_bi = case_when(v2elmulpar_osp <= 1 ~ 0,
v2elmulpar_osp > 1 ~ 1,
is.na(v2elmulpar_osp) ~ 0))
table(vdem$v2elmulpar_osp_bi) # compare Lührmann et al. 2018
ggplot(vdem, aes(x = wth_regime, y = v2elmulpar_osp_bi))  +
geom_jitter()
ggplot(vdem, aes(x = wth_regime, y = as.factor(v2elmulpar_osp_bi)))  +
geom_jitter()
ggplot(vdem, aes(x = wth_regime, y = as.factor(v2elmulpar_osp_bi)))  +
geom_jitter() +
labs(x = "Regime types by Wahman et al.",
y = "Multiparty elections")
vdem <- vdem %>%
mutate(v2elmulpar_osp_bi = case_when(v2elmulpar_osp_bi==1 ~ "Yes",
v2elmulpar_osp_bi==0 ~ "no"))
ggplot(vdem, aes(x = wth_regime, y = as.factor(v2elmulpar_osp_bi)))  +
geom_jitter() +
labs(x = "Regime types by Wahman et al.",
y = "Multiparty elections")
vdem <- vdem %>%
group_by(cown) %>%
fill(v2elmulpar_osp)
summary(vdem$v2elmulpar_osp) # compare Lührmann et al. 2018
vdem <- vdem %>%
mutate(v2elmulpar_osp_bi = case_when(v2elmulpar_osp <= 1 ~ 0,
v2elmulpar_osp > 1 ~ 1,
is.na(v2elmulpar_osp) ~ 0))
table(vdem$v2elmulpar_osp_bi) # compare Lührmann et al. 2018
vdem <- vdem %>%
mutate(v2elmulpar_osp_bi = case_when(v2elmulpar_osp_bi==1 ~ "Yes",
v2elmulpar_osp_bi==0 ~ "No"))
review_figure <- ggplot(vdem, aes(x = wth_regime, y = as.factor(v2elmulpar_osp_bi)))  +
geom_jitter() +
labs(x = "Regime types by Wahman et al.",
y = "Multiparty elections")
review_figure
ggsave("calculations/Output/review_figure.png", height = 14, width = 24, units= c("cm"))
ggsave("calculations/Output/review_figure.pdf", height = 14, width = 24, units= c("cm"))
getwd()
ggsave("M:/Promotion/Paper/Gender Inequality/calculations/Output/review_figure.png", height = 14, width = 24, units= c("cm"))
